<?php

require_once dirname(__FILE__) . '/../../bootstrap.unit.php';

class ForageFieldTest extends PHPUnit_Framework_TestCase
{
  private $field;

  public function setUp()
  {
    $this->field = new ForageField('name', 'content');
  }

  public function tearDown()
  {
    unset($this->field);
  }

  public function testCreation()
  {
    $this->assertEquals($this->field->name, 'name', 'Field name should be set.');
    $this->assertEquals($this->field->value, 'content', 'Field value should be set.');
  }
  
  public function testPropertyAccess()
  {
    $this->field->setProperty('boost', '1.2');
    $this->assertEquals('1.2', $this->field->getProperty('boost'));
    $this->assertEquals('default', $this->field->getProperty('noprop', 'default'));
  }

  /**
   * @expectedException InvalidArgumentException
   */
  public function testInvalidPropertyAccessThrowsException()
  {
    $this->field->blah;
  }

  public function testStringEvaluation()
  {
    $this->assertEquals("content", "".$this->field);
  }
}
